package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppMingxiMeilizhi;
import com.vf.admin.miaodong.entity.AppMingxiMeilizhi;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 账单明细-充值
 */
@Repository
public class AfterMingxiMeilizhiDao extends BaseDao<AppMingxiMeilizhi> {

    /**
     * 查询列表
     */
    public List<AppMingxiMeilizhi> findList(Map<String,Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_mingxi_meilizhi where 1=1  ");
        if(StringEx.isNotNull(paraMap.get("startDate"))){
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  >=  ? ");
            paramList.add(paraMap.get("startDate"));
        }
        if(StringEx.isNotNull(paraMap.get("endDate"))){
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  <=  ? ");
            paramList.add(paraMap.get("endDate"));
        }
            if(StringEx.isNotNull(paraMap.get("nick"))){
            sbStr.append(" and nick like ? ");
            paramList.add("%"+paraMap.get("nick")+"%");
        }
        if(StringEx.isNotNull(paraMap.get("phone"))){
            sbStr.append(" and phone like ? ");
            paramList.add("%"+paraMap.get("phone")+"%");
        }
        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppMingxiMeilizhi.class,splitPage);
    }


    /**
     * 详情
     */
    public AppMingxiMeilizhi get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_mingxi_meilizhi where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppMingxiMeilizhi.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppMingxiMeilizhi appMingxiMeilizhi) {
        if (appMingxiMeilizhi!=null && appMingxiMeilizhi.getId() != null && appMingxiMeilizhi.getId() > 0) {
            this.update(appMingxiMeilizhi);
        } else {
            appMingxiMeilizhi.setId(this.add(appMingxiMeilizhi));
        }
    }

}
